package com.booza.dao;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.booza.model.Room;

@Transactional
public class RoomDAOImpl implements RoomDAO
{
	@Autowired
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory()
	{
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory)
	{
		this.sessionFactory = sessionFactory;
	}

	@Override
	public Room findById(Integer id)
	{
		return (Room) sessionFactory.getCurrentSession().get(Room.class, id);
	}

	@Override
	public Room findByName(String name)
	{
		return (Room) sessionFactory.getCurrentSession().createCriteria(Room.class).add(Restrictions.like("name", name))
				.uniqueResult();
	}
}
